home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 6039 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.5 KB  |  81 lines

  1. Path: news.cuny.edu!x60cc
  2. From: SHAHZAD ANJUM MALIK <X60CC@CUNYVM.CUNY.EDU>
  3. Newsgroups: comp.lang.c
  4. Subject: A Linked List Problem
  5. Date: Thu, 22 Feb 1996 01:51:13 EST
  6. Message-ID: <96053.015114X60CC@CUNYVM.CUNY.EDU>
  7. NNTP-Posting-Host: cunyvm.cuny.edu
  8. Disclaimer: Author bears full responsibility for this post
  9.  
  10. Hi!
  11.     I am trying to create a small program using Linked Lists. Actually, I
  12. am planning to use Linked Lists in Linked Lists. A simple application of the
  13. program would be to add a customer name etc and then add a magazine to be
  14. subscribed to the customer, and if the customer wants add a 2nd and 3rd and
  15. so on. For adding new customers I am using Linked Lists of nested structures.
  16. Structures look like this:
  17.  
  18. struct CustName
  19.      {
  20.      char LastName[15];
  21.      char ID#[5];
  22.      };
  23. struct Magazine
  24.      {
  25.      char MagName[20];
  26.      struct Magazine *nextMag;
  27.      };
  28. struct CustProfile
  29.      {
  30.      struct CustName Name;
  31.      struct Magazine Mag;
  32.      struct CustProfile *next;
  33.      };
  34. typedef struct CustProfile ELEMENT;
  35. typedef ELEMENT *LINK;
  36.  
  37.  
  38.  
  39. main()
  40. {
  41.       LINK current, head;
  42.       head = NULL;
  43.       NewNode = (LINK)malloc(sizeof(ELEMENT));
  44.       if(head == NULL)
  45.         head = current = NewNode;
  46.       else
  47.       {
  48.         current = head;
  49.         while (current->next ! = NULL)
  50.            current = current->next;
  51.         current->next = NewNode;
  52.         current = NewNode;
  53.       }
  54.  
  55.       printf("Enter Customer Name: ");
  56.       gets(current->Name.LastName);
  57.       printf("Enter Mag Name");
  58.       gets(current->Mag.MagName);
  59.       printf("Enter Second Mag Name");
  60.       gets(current->Mag.nextMag->MagName);
  61.  
  62.       current->Mag = current->Mag.nextMag;
  63.       current->next = NULL;
  64. }
  65.  
  66.  
  67.      The problem is that the complier (MSC 6.00) gives syntax error on the
  68.      2nd last line. I have been trying to remove the mistake for several
  69.      days but useless. The error for "current->Mag = current->Mag.nextMag"
  70.      is " Erro No. '=' incompatible types. I will be extremely grateful if
  71.      someone could help me in either removing the error or giving me a simpler
  72.      idea of implementing the same code in a different way. My problem is
  73.      that I want to use LinkedLists and not arrays. Also I want to use Linked
  74.      Lists in Linked Lists. In the above program, I uesd Magazine structure
  75.      which has a pointer field to the next Magazine structure. Similarly
  76.      the main structure CustProfile also has a pointer pointing to the next
  77.      structure.
  78.  
  79.      I'll really appreciate if someone please send a solution at the earliest
  80.      possible.   Thank you.
  81.